package com.free.normal;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;

/**
 * <p>
 * Title: Eclipse Plugin Development
 * </p>
 * <p>
 * Description: Free download
 * </p>
 * <p>
 * mail: ganshm@gmail.com
 * </p>
 */

public class HelloWorldList
{
    
    // 列表项
    private static final String[] ITEMS = {"Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform",
        "Victor", "Whiskey", "X-Ray", "Yankee", "Zulu"};
    
    public static void main(String[] args)
    {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        // 添加只能单选的列表框
        List single = new List(shell, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);
        // 添加列表项
        for (int i = 0, n = ITEMS.length; i < n; i++)
        {
            single.add(ITEMS[i]);
        }
        // 选择第5项
        single.select(4);
        // 添加可多选的列表框
        List multi = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
        // 添加列表项
        multi.setItems(ITEMS);
        // 选择10到第12项
        multi.select(9, 11);
        shell.open();
        while (!shell.isDisposed())
        {
            if (!display.readAndDispatch())
            {
                display.sleep();
            }
        }
        display.dispose();
    }
}
